package com.tour.controller;


import com.tour.config.ResponseWrapper;
import com.tour.entity.Post;
import com.tour.service.impl.PostServiceImpl;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import lombok.Data;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import org.springframework.stereotype.Controller;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author lel
 * @since 2020-12-30
 */

@RestController
@Api(tags = "游记管理")
@RequestMapping("/app/post")
public class PostController {

    @Autowired
    PostServiceImpl postServiceImpl;

    @ApiOperation("增加游记")
    @PostMapping("/addPost")
    public ResponseWrapper addPost(@RequestBody Post post) {
        ResponseWrapper wrapper = postServiceImpl.addPost(post);
        return wrapper;
    }
    @ApiOperation("按类别获取游记")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "category",value = "游记类别"),
            @ApiImplicitParam(name = "pageSize",value = "每页展示的数据条数",defaultValue = "10"),
            @ApiImplicitParam(name = "pageNum",value = "页码数",defaultValue = "1")
    })
    @GetMapping("/getPost")
    public ResponseWrapper findPostByCategory(@RequestParam(name = "category",required = false)String category,
                                              @RequestParam(name = "pageSize",defaultValue = "10")Integer pageSize,
                                              @RequestParam(name = "pageNum",defaultValue = "1")Integer pageNum){
        ResponseWrapper wrapper = postServiceImpl.findPostByCategory(category,pageSize,pageNum);
        return wrapper;
    }
    @ApiOperation("删除游记")
    @ApiImplicitParam(name = "postId",value = "游记id")
    @DeleteMapping("deletePost")
    public ResponseWrapper deletePost(@RequestParam(name = "postId",required = true)Integer postId){
        ResponseWrapper wrapper = postServiceImpl.delPost(postId);
        return wrapper;
    }
    @ApiOperation("查询一个游记")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "postId",value = "游记id"),
            @ApiImplicitParam(name = "pageSize",value = "每页展示的数据条数",defaultValue = "10"),
            @ApiImplicitParam(name = "pageNum",value = "页码数",defaultValue = "1")
    })
    @GetMapping("/findPostByPostId")
    public ResponseWrapper findPostByPostId(@RequestParam(name = "postId")Integer postId,
                                            @RequestParam(name = "pageSize",defaultValue = "10")Integer pageSize,
                                            @RequestParam(name = "pageNum",defaultValue = "1")Integer pageNum){
        ResponseWrapper wrapper = postServiceImpl.findPostById(postId,pageSize,pageNum);
        return wrapper;
    }
    @ApiOperation("查询自己的游记")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "userId",value = "用户的id"),
            @ApiImplicitParam(name = "pageSize",value = "每页展示的数据条数",defaultValue = "10"),
            @ApiImplicitParam(name = "pageNum",value = "页码数",defaultValue = "1")
    })
    @GetMapping("/findByUserId")
    public ResponseWrapper findByUserId(@RequestParam(name = "userId")Integer userId,
                                        @RequestParam(name = "pageSize",defaultValue = "10")Integer pageSize,
                                        @RequestParam(name = "pageNum",defaultValue = "1")Integer pageNum){
        ResponseWrapper wrapper = postServiceImpl.findPostByuserId(userId,pageSize,pageNum);
        return wrapper;
    }
    @ApiOperation("模糊查询游记")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "content",value = "输入框查询的值"),
            @ApiImplicitParam(name = "pageSize",value = "每页展示的数据条数",defaultValue = "10"),
            @ApiImplicitParam(name = "pageNum",value = "页码数",defaultValue = "1")
    })
    @GetMapping("/searchPost")
    public ResponseWrapper searchPost(@RequestParam(name = "content",required = false)String content,
                                      @RequestParam(name = "pageSize",defaultValue = "10")Integer pageSize,
                                      @RequestParam(name = "pageNum",defaultValue = "1")Integer pageNum){
        ResponseWrapper wrapper = postServiceImpl.seachPost(content,pageSize,pageNum);
        return wrapper;
    }
    @ApiOperation("修改点赞数")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "postId",value = "游记的id"),
            @ApiImplicitParam(name = "likes",value = "点赞数")
    })
    @PutMapping("/updateLikes")
    public ResponseWrapper updateLikes(@RequestParam(name = "postId")Integer postId,
                                       @RequestParam(name = "likes")Integer likes){
        ResponseWrapper wrapper = postServiceImpl.updateLikes(postId,likes);
        return wrapper;
    }
}
